/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package webOffline;

import java.util.ArrayList;
import javax.swing.tree.DefaultMutableTreeNode;

/**
 *
 * @author Do Viet Trung
 */
public class ProjectDownloadLinks {
    private String url;
    private int level;
    private String name;
    private String saveTo;
    private boolean finish;

    private ArrayList <ProjectDownloadLinks> arrayLinks;
    private ArrayList <ProjectDownloadFiles> arrayFiles;
    private ArrayList <String> arrayResourceLinks;
    private ArrayList <String> arrayResourcePaths;
    private DefaultMutableTreeNode node;
    private String PROJECT_DIR = WebOffline.projectsPath;

    ProjectDownloadLinks()  throws Exception {
//        node = new DefaultMutableTreeNode(url);
        arrayResourceLinks = new ArrayList<String>();
        arrayResourcePaths = new ArrayList<String>();

        arrayLinks = new ArrayList<ProjectDownloadLinks>();
        arrayFiles = new ArrayList<ProjectDownloadFiles>();
    }

    ProjectDownloadLinks (ProjectAddress projAdd) throws Exception  {
        this.url = projAdd.getAddress();
        this.saveTo = projAdd.getSaveTo();
        node = new DefaultMutableTreeNode(projAdd.getProjectName());
        arrayResourceLinks = new ArrayList<String>();
        arrayResourcePaths = new ArrayList<String>();
        arrayLinks = new ArrayList<ProjectDownloadLinks>();
        arrayFiles = new ArrayList<ProjectDownloadFiles>();
    }

    ProjectDownloadLinks (String url) throws Exception {
        this.url = url;
        this.saveTo = PROJECT_DIR;
        node = new DefaultMutableTreeNode(url);
        arrayResourceLinks = new ArrayList<String>();
        arrayResourcePaths = new ArrayList<String>();
        arrayLinks = new ArrayList<ProjectDownloadLinks>();
        arrayFiles = new ArrayList<ProjectDownloadFiles>();
    }

    ProjectDownloadLinks (String url, int level, String saveName, String saveDir) throws Exception {
        this.url = url;
        this.level = level;
        this.name = saveName;
        this.saveTo = saveDir;
        node = new DefaultMutableTreeNode(url);
        arrayResourceLinks = new ArrayList<String>();
        arrayResourcePaths = new ArrayList<String>();
        arrayLinks = new ArrayList<ProjectDownloadLinks>();
        arrayFiles = new ArrayList<ProjectDownloadFiles>();
    }

    public DefaultMutableTreeNode getNode() {
        return node;
    }

    public ArrayList<ProjectDownloadLinks> getArrayLinks() {
        return arrayLinks;
    }

    public void setArrayLinks(ArrayList<ProjectDownloadLinks> arrayLinks) {
        this.arrayLinks = arrayLinks;
    }

    public ArrayList<ProjectDownloadFiles> getArrayFiles() {
        return arrayFiles;
    }

    public void setArrayFiles(ArrayList<ProjectDownloadFiles> arrayFiles) {
        this.arrayFiles = arrayFiles;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public boolean isFinish() {
        return finish;
    }

    public void setFinish(boolean finish) {
        this.finish = finish;
    }

    public String getSaveTo() {
        return saveTo;
    }

    public void setSaveTo(String saveTo) {
        if (saveTo.equals("") || saveTo == null) {
            this.saveTo = PROJECT_DIR;
        }
        else {
            this.saveTo = saveTo;
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean hasURL (String url) {
        for (int idx = 0; idx < arrayLinks.size(); ++idx) {
            if (arrayLinks.get(idx).getUrl().contains(url)) {
                return true;
            }
        }
        return false;
    }

    public boolean addToArrayLinks (ProjectDownloadLinks proj) {
        this.arrayLinks.add(proj);
        
        return true;
    }

    public boolean addToArrayFiles (ProjectDownloadFiles proj) {
        this.arrayFiles.add(proj);
        return true;
    }

    public ArrayList<String> getArrayResourceLinks() {
        return arrayResourceLinks;
    }

    public void setArrayResourceLinks(ArrayList<String> arrayResourceLinks) {
        this.arrayResourceLinks = arrayResourceLinks;
    }

    public ArrayList<String> getArrayResourcePaths() {
        return arrayResourcePaths;
    }

    public void setArrayResourcePaths(ArrayList<String> arrayResourcePaths) {
        this.arrayResourcePaths = arrayResourcePaths;
    }

    public boolean addToArrayResourceLinks (String url) {
        this.arrayResourceLinks.add(url);
        
        return true;
    }

    public boolean addToArrayResoucePaths (String url) {
        this.arrayResourcePaths.add(url);
        return true;
    }
}
